/**
 * Copyright 2007 Igor Chaves Cananéa
 *
 * This file is part of PBSFW
 *
 * PBSFW is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * PBSFW is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef _EXCEPTIONS_H_
#define _EXCEPTIONS_H_

#include "defines.h"
#include <exception>

#define DECLARE_EXCEPTION(Class, Msg) 	class Class: public BaseException { \
		public: \
			Class(const char *msg = Msg) \
				: BaseException(msg) {} \
	};

/**
 * This is the base exception class that should be the base class of any other
 * exception to be created. There is a macro that eases the creation of any new
 * exception. The macro can be used like this:
 *
 * DECLARE_EXCEPTION(ClassName, Message)
 *
 * where ClassName is the name of the new exception and Message is what will
 * be shown when the what() method is invoked. The Message MUST BE a double
 * quoted enclosed string ("example").
 */
class BaseException: public std::exception {
	private:
		const char *msg;

	public:
		BaseException(const char *msg) : msg(msg) {}

		/**
		 * Returns the exception message.
		 *
		 * @return the exception message.
		 */
		const char *what() const throw() { return this->msg; }
};

#endif
